home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-05 / netid.zip / NETID.ASM < prev    next >
Assembly Source File  |  1992-09-03  |  13KB  |  346 lines

  1. ;
  2. ; Simple program to extract the user's name from netware and place it in
  3. ; an environment variable "USER".  
  4. ;
  5. ; Public Domain - credits to Matthew Staben, Staben Technologies
  6. ;                                            811 West 14th Avenue
  7. ;                                            Spokane, WA  99204
  8. ;
  9.  
  10.  
  11. .model small
  12. .code
  13.  
  14.                 ;===============================:
  15.                 ; first, test for MS-DOS or 4DOS:
  16.                 ;===============================:
  17.                 mov     ax, 0D44Dh              ; 4DOS swap area
  18.                 mov     bx, 0
  19.                 int     2Fh                     ; and interrupt it
  20.                 ;===============================:
  21.                 ;IF ax = 44DD, 4DOS is used.    :
  22.                 ;===============================:
  23.                 cmp     ax, 44DDh               ; compare the deal
  24.                 je      IS_4DOS                 ; and if equal, its 4DOS
  25.                 mov     ax, 352Eh               ; find the master env
  26.                 int     21h
  27.                 mov     es, [es:2Ch]            ; es = environment segment
  28.                 jmp     short   dos_checked     ; jump past 4dos stuff
  29.         is_4dos:
  30.                 mov     es, cx                  ; es = 4dos environment segment
  31.                 mov     es, [es:2Ch]
  32.         dos_checked:            
  33.                 mov     [cs:envseg], es
  34.                 xor     di, di                  ; point to start of env in es:di
  35.                 cld                             ; scan in forward
  36. FIND_STRING:                                    ; - loop thru 1 by 1
  37.                 test    [byte ptr es:[di]], -1  ; end of env?
  38.                 jnz     check_string            ; nope... continue
  39.                 jmp     short   no_environment  ; error...
  40. CHECK_STRING:           
  41.                 push    cs
  42.                 pop     ds
  43.                 mov     si, offset ENVSTR       ; point to USERNAME
  44.                 mov     bx, di                  ; save ptr to start
  45.                 mov     cx, envlen              ; length of envstr
  46.                 repe    cmpsb                   ; compare
  47.                 je      ALL_PASSED              ; found it!
  48.                 mov     di, bx                  ; restore ptr to start
  49.                 xor     al, al                  ; scan for end of string
  50.                 mov     cx, -1                  ; FFFF <- cx
  51.                 repne   scasb
  52.                 jmp     short   find_string     ; go back for next string
  53.                 
  54. ALL_PASSED:
  55.                 mov     [cs:envoff], di
  56.                 clc
  57.                 mov     [cs:onezero], 0
  58.                 jmp     BEGIN
  59.                 
  60. NO_ENVIRONMENT:
  61.                 ;===========================:
  62.                 ; This procedure is called  :
  63.                 ; if the environment string :
  64.                 ; does not exist.           :
  65.                 ;===========================:
  66.                 ; so, create it!            :
  67.                 ;===========================:
  68.                 
  69.                 mov     [cs:onezero],2
  70.                 mov     ax, [cs:envseg]
  71.                 mov     es, ax
  72.                 xor     di, di
  73.                 
  74.                 ; look for pair of zeros, the second zero is the new begin
  75. lookfor:                
  76.                 mov     ah, [byte ptr es:[di]]
  77.                 cmp     ah, 0
  78.                 je      first_zero
  79.                 inc     di
  80.                 jmp     lookfor
  81. first_zero:
  82.                 inc     di
  83.                 mov     ah, [byte ptr es:[di]]
  84.                 cmp     ah, 0
  85.                 jne     lookfor
  86.                 
  87. is_zero:
  88.                 mov     [byte ptr es:[di]], 85
  89.                 inc     di
  90.                 mov     [byte ptr es:[di]], 83
  91.                 inc     di
  92.                 mov     [byte ptr es:[di]], 69
  93.                 inc     di
  94.                 mov     [byte ptr es:[di]], 82
  95.                 inc     di
  96.                 mov     [byte ptr es:[di]], 61    
  97.                 inc     di
  98.                 mov     [cs:envoff], di
  99.                 jmp     begin
  100.  
  101. SHOW_MESSAGE:
  102.                 mov     ah, 09h
  103.                 int     21h
  104.                 
  105. EXIT_OUT:
  106.                 jmp     bye_bye
  107. BEGIN:
  108.  
  109. MODIFY_ENV:
  110.                 ;==================================================:
  111.                 ; Let's get the username and slip into the env     :
  112.                 ;==================================================:
  113.                 
  114.                 mov     AH,0DCh                 ; function to get connection #
  115.                 int     21h
  116.                 mov     CS:ConnectionNumber,AL
  117.  
  118.                 mov     AH,0E3h                 ; log request function #
  119.  
  120.                 mov     DX,seg cs:RequestBuffer
  121.                 mov     DS,DX
  122.                 mov     DX,seg cs:ReplyBuffer
  123.                 mov     ES,DX
  124.                 lea     SI,cs:RequestBuffer        ;  DS:SI points to Request Buffer
  125.                 lea     DI,cs:ReplyBuffer          ;  ES:DI points to Reply Buffer
  126.                                               
  127.                 int     21h
  128.  
  129. ;  Return the name
  130.  
  131.        WRITE_OUT:
  132.                 ; here, we actually write out the environment.       
  133.                 mov     ax, seg cs:objectname
  134.                 mov     es, ax
  135.                 mov     di, offset cs:objectname
  136.                 mov     [cs:objectoff], di
  137.                 mov     [cs:objectseg], es
  138.                 mov     ax, cs
  139.                 mov     ds, ax
  140.                 mov     si, offset safearea
  141.                 xor     dx, dx
  142.                 xor     bx, bx
  143.                 xor     cx, cx
  144.                 
  145.                 cmp     [cs:onezero], 2
  146.                 jne     REPLACEUPTO
  147.                 
  148.                 ; 
  149.                 ; just fill it out and add two zeros
  150.                 ;
  151.           APPEND:
  152.                 mov     es, [cs:objectseg]
  153.                 mov     di, [cs:objectoff]
  154.                 mov     ah, [byte ptr es:[di]]
  155.                 cmp     ah, 0
  156.                 je      addtwo
  157.                 inc     [cs:objectoff]
  158.                 mov     es, [cs:envseg]
  159.                 mov     di, [cs:envoff]
  160.                 inc     [cs:envoff]
  161.                 mov     [byte ptr es:[di]], ah
  162.                 jmp     append
  163.       addtwo:
  164.                 mov     es, [cs:envseg]
  165.                 mov     di, [cs:envoff]
  166.                 jmp     addtwozeros
  167.  
  168.       samelength:
  169.                 cmp     ah, 0
  170.                 jne     retsame
  171.                 jmp     did_it
  172.                                 
  173.       REPLACEUPTO:
  174.                 ; 
  175.                 ; replace the environment up to the first zero
  176.                 ;
  177.                 mov     es, [cs:objectseg]
  178.                 mov     di, [cs:objectoff]
  179.                 mov     ah, [byte ptr es:[di]]  ; next net buffer char
  180.                 mov     es, [cs:envseg]
  181.                 mov     di, [cs:envoff]
  182.                 mov     al, [byte ptr es:[di]]
  183.                 ; check if both are zero
  184.                 cmp     al, ah
  185.                 je      samelength
  186.            retsame:
  187.                 ; check if zero has been reached in environment
  188.                 cmp     al, 0
  189.                 je      ENDREPLACE
  190.                 ; check if zero has been reached in net-buffer
  191.                 cmp     ah, 0
  192.                 je      ENDNETBUF
  193.                 mov     es, [cs:envseg]
  194.                 mov     di, [cs:envoff]
  195.                 mov     [byte ptr es:[di]], ah
  196.                 inc     [cs:envoff]
  197.                 inc     [cs:objectoff]
  198.                 jmp     REPLACEUPTO
  199.  
  200.       ENDNETBUF:
  201.                 ; 
  202.                 ; scan thru environment to next char, saving the current
  203.                 ; position in the environment for replacing
  204.                 ;
  205.                 mov     di, [cs:envoff]
  206.                 mov     [cs:startpos], di
  207.                 ; find a zero
  208.          envscan:
  209.                 inc     di
  210.                 mov     ah, [byte ptr es:[di]]
  211.                 cmp     ah, 0
  212.                 je      endenvscan
  213.                 jmp     envscan
  214.          endenvscan:
  215.                 mov     [cs:envoff], di
  216.                 
  217.       ENDREPLACE:
  218.                 ; 
  219.                 ; save the rest of the environment in the buffer
  220.                 ;
  221.                 mov     di, [cs:envoff]
  222.                 cmp     [cs:startpos], 0
  223.                 jne     checkstart
  224.                 mov     [cs:startpos], di
  225.          checkstart:
  226.                 mov     es, [cs:envseg]
  227.                 mov     di, [cs:envoff]
  228.                 mov     ah, [byte ptr es:[di]]
  229.                 cmp     ah, 0
  230.                 jne     notzero
  231.                 inc     di
  232.                 mov     ah, [byte ptr es:[di]]
  233.                 dec     di
  234.                 cmp     ah, 0
  235.                 je      checkout
  236.          
  237.          notzero:
  238.                 mov     ah, [byte ptr es:[di]]
  239.                 mov     [byte ptr ds:[si]], ah
  240.                 inc     [cs:envoff]
  241.                 inc     si
  242.                 inc     dl
  243.                 jmp     checkstart
  244.       
  245.          checkout:
  246.        
  247.       FILLENVIRONMENT:
  248.                 ; 
  249.                 ; if the buffer was too long, we still have some chars to
  250.                 ; slip into the environment from the network buffer
  251.                 ;
  252.                 mov     es, [cs:objectseg]
  253.                 mov     di, [cs:objectoff]
  254.                 mov     ah, [byte ptr es:[di]]
  255.                 cmp     ah, 0
  256.                 je     fillitup
  257.            fillnet:
  258.                 mov     es, [cs:objectseg]
  259.                 mov     di, [cs:objectoff]
  260.                 mov     ah, [byte ptr es:[di]]
  261.                 cmp     ah, 0
  262.                 je      fillitup
  263.                 inc     [cs:objectoff]
  264.                 mov     es, [cs:envseg]
  265.                 mov     di, [cs:startpos]
  266.                 mov     [byte ptr es:[di]], ah
  267.                 inc     [cs:startpos]
  268.                 jmp     fillnet
  269.                 
  270.            fillitup:
  271.                 mov     di, [cs:startpos]
  272.                 mov     [cs:envoff], di
  273.                 mov     ax, cs
  274.                 mov     ds, ax
  275.                 mov     si, offset safearea
  276.                 inc     dl
  277.            filloop:
  278.                 mov     di, [cs:envoff]
  279.                 mov     es, [cs:envseg]
  280.                 mov     ah, [byte ptr ds:[si]]
  281.                 inc     si
  282.                 mov     [byte ptr es:[di]], ah
  283.                 inc     [cs:envoff]
  284.                 inc     cx
  285.                 cmp     cx, dx
  286.                 je      addtwozeros
  287.                 jmp     filloop
  288.          
  289.            addtwozeros:
  290.                 mov     [byte ptr es:[di]], 0
  291.                 inc     di
  292.                 mov     [byte ptr es:[di]], 0
  293.  
  294. did_it:
  295.                 mov     ax, cs
  296.                 mov     ds, ax
  297.                 mov     dx, offset ACTION      ; point to finished mssg
  298.                 jmp     show_message
  299.         
  300. bye_bye:
  301.                 mov     ah, 4Ch
  302.                 int     21h             
  303.                 
  304. ACTION          DB      0Ah,0Dh,0Ah,0Dh
  305.                 DB      'Bovay Northwest, Inc.', 0Ah, 0Dh
  306.                 DB      '---------------------', 0Ah, 0Dh
  307.                 DB      'Netware Username Extraction Facility',0Ah,0Dh
  308.                 DB      0Ah,0Dh
  309.                 DB      'The currently logged in user''s name ',0Ah,0Dh
  310.                 DB      'has been extracted to the environment',0Ah,0Dh
  311.                 DB      'under USER.'
  312.                 DB      0AH,0Dh
  313.                 DB      '$'
  314.  
  315. ;============================================:
  316. ; Variables which are internally used by the :
  317. ; program.                                   :
  318. ;============================================:
  319. safearea        DB      512 dup ( ? )          ; temp storage buffer
  320. EMPTYSPOT       DB      'D'
  321. ENVSTR          DB      'USER='                 ; Env. variable to find
  322. ENVLEN          EQU     5                       ; length of env variable
  323. envseg          DW      0                        ; environment seg
  324. envoff          DW      0                        ; environment offset
  325. objectseg       DW      0                       ; object segment
  326. objectoff       DW      0                       ; object offset
  327. startpos        DW      0                       ; network buffer too short
  328. onezero         DB      0                       ; was it appended?
  329.  
  330.  
  331. RequestBuffer           Label   Byte
  332. PacketLengthLow         db      2               ; request buffer 2 bytes long
  333. PacketLengthHigh        db      0
  334. Function                db      22              ; sub function to get user info
  335. ConnectionNumber        db      ?               ; logical connection number
  336.  
  337. ReplyBuffer             Label   Byte
  338. ReturnLengthLow         db      62              ; Reply is 62 bytes long
  339. ReturnLengthHigh        db      0
  340. UniqueID                dd      ?               ; Station's ID #
  341. Typex                   dw      ?
  342. ObjectName              db      48 dup ( ? )    ; USERNAME 1-47 characters
  343. LogTime                 db      8  dup ( ? )    ; Time user logged in
  344.  
  345. end                
  346.